package com.hf.work04;

import java.util.Random;
import java.util.Scanner;

public class StudentClass {
    /**
     * 学生数组
     */
    Student[] students;
    /**
     * 学生个数
     */
    int len;
    /**
     * 打印成绩
     */
    public void printStudentClass(){
        if (students != null && students.length > 0){
            //遍历学生信息
            for (Student stu : students){
                //调用打印方法
                stu.priStu();
            }
        }
    }
    /**
     * 构造方法
     */
    public StudentClass(int len) {
        this.len = len;
        //根据人数初始化数据
        if (len > 0){
            students = new Student[len];
        }else {
            students = new Student[5];
        }
        initStudentArr(students);
    }

    /**
     * 使用随机数初始化学生数组
     */
    public void initStudentArr(Student[] student){
        //创建随机数对象
        Random random = new Random();
        Scanner sc = new Scanner(System.in);
        //初始化学生数组
        for (int i = 0;i < student.length; i++){
            //随机产生学生系别
            int type = random.nextInt(3);
            if (type == 0){
                System.out.println("请输入英语系的学生姓名：");
                EnglishDepartment englishDepartment = new EnglishDepartment();
                //从控制台输入
                englishDepartment.setStuName(sc.next());
                System.out.println("请输入学号：");
                englishDepartment.setStuNo(sc.nextInt());
                System.out.println("请输入年龄：");
                englishDepartment.setStuAge(sc.nextInt());
                System.out.println("请输入性别：");
                englishDepartment.setStuSex(sc.next());
                System.out.println("请输入英语演讲成绩：");
                englishDepartment.setLectrure(sc.nextInt());
                System.out.println("请输入期中成绩：");
                englishDepartment.setStuMiddle(sc.nextInt());
                System.out.println("请输入期末成绩：");
                englishDepartment.setStuFinal(sc.nextInt());
                //初始化数组元素
                student[i] = englishDepartment;
            }else if (type == 1){
                ComputerDepartment computerDepartment = new ComputerDepartment();
                System.out.println("请输入计算机系的学生姓名：");
                computerDepartment.setStuName(sc.next());
                System.out.println("请输入学号：");
                computerDepartment.setStuNo(sc.nextInt());
                System.out.println("请输入年龄：");
                computerDepartment.setStuAge(sc.nextInt());
                System.out.println("请输入性别：");
                computerDepartment.setStuSex(sc.next());
                System.out.println("请输入操作能力成绩：");
                computerDepartment.setOperationAble(sc.nextInt());
                System.out.println("请输入英语写作成绩：");
                computerDepartment.setEnglishWrite(sc.nextInt());
                System.out.println("请输入期中成绩：");
                computerDepartment.setStuMiddle(sc.nextInt());
                System.out.println("请输入期末成绩：");
                computerDepartment.setStuFinal(sc.nextInt());
                //初始化数组元素
                student[i] = computerDepartment;
            }else {
                LetterDepartment letterDepartment = new LetterDepartment();
                System.out.println("请输入文学系的学生姓名：");
                letterDepartment.setStuName(sc.next());
                System.out.println("请输入学号：");
                letterDepartment.setStuNo(sc.nextInt());
                System.out.println("请输入年龄：");
                letterDepartment.setStuAge(sc.nextInt());
                System.out.println("请输入性别：");
                letterDepartment.setStuSex(sc.next());
                System.out.println("请输入演讲成绩：");
                letterDepartment.setLectrure(sc.nextInt());
                System.out.println("请输入期中成绩：");
                letterDepartment.setStuMiddle(sc.nextInt());
                System.out.println("请输入期末成绩：");
                letterDepartment.setStuFinal(sc.nextInt());
                //初始化数组元素
                student[i] = letterDepartment;
            }
        }
    }
}
